//
//  EXObjectReferenceInCollection.m
//  ORM
//
//  Created by PH on 21.12.09.
//  Copyright 2009-2010 Codesign. All rights reserved.
//

#import "EXObjectReferenceInCollection.h"

@implementation EXObjectReferenceInCollection

@synthesize objectID;

- (id)_initWithObjectID:(NSString*)_objectID {
	if ((self = [super init])) {
		objectID = [_objectID retain];
	}
	return self;
}

- (id)initWithData:(NSData*)data {
	if ((self = [super init])) {
		NSAssert(data != nil, @"UTF-8 string is NULL");
		objectID = [[NSString alloc] initWithBytes: [data bytes] length: [data length] encoding: NSUTF8StringEncoding];
		if (objectID == nil) NSLog(@"Object ID is nil for '%s'", [data bytes]);
	}
	return self;
}

- (id)initWithCoder:(NSCoder*)coder {
	if ((self = [super init])) {
		objectID = [[coder decodeObjectForKey: @"objectID"] retain];
	}
	return self;
}

- (NSData*)dataRepresentation {
	return [objectID dataUsingEncoding: NSUTF8StringEncoding];
}

- (NSString*)objectID {
	return objectID;
}

- (void)encodeWithCoder:(NSCoder*)coder {
	[coder encodeObject: objectID forKey: @"objectID"];
}

- (void)dealloc {
	[objectID release];
	[super dealloc];
}

@end
